import { BasicColumn, FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { UploadBizType } from '/@/enums/uploadEnum';
import { TenantType } from '/@/enums/bizEnum'
import { useUserStore } from '/@/store/modules/user';

const userStore = useUserStore()

export const columns: BasicColumn[] = [
  {
    title: '租户套餐',
    width: 150,
    dataIndex: 'name',
  },
  {
    title: '租户类型',
    width: 80,
    customRender: (data) => {
      const { text, record } = data as any
      let tenantTypeName = record.tenantTypeName
      let color;
      if (record.id === '1') {
        color = 'purple'
        tenantTypeName = '平台端'
      }else if (text === '2') {
        color = 'blue'
      } else if (text === '3') {
        color = 'green'
      } else if (text === '4') {
        tenantTypeName = '子租户'
        color = 'cyan'
      }
      return render.renderTag(tenantTypeName, color)
    },
    dataIndex: 'tenantType',
  },
  {
    title: '状态',
    width: 64,
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = 'green'
      if (text === '0') {
        color = 'red'
      }
      return render.renderTag(render.renderDict(text, 'data_use_status'), color)
    },
  },
  {
    title: '创建时间',
    width: 160,
    dataIndex: 'createdAt',
  },
  {
    title: '创建者',
    width: 90,
    dataIndex: 'createdBy',
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '套餐名',
    component: 'Input',
    // colProps: {span: 24},
  }
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'name',
    label: '套餐名称',
    component: 'Input',
    required: true
  },
  {
    field: 'tenantType',
    label: '租户类型',
    component: 'JDictSelectTag',
    defaultValue: '3',
    componentProps: {
      type: 'radio',
      dictCode: 'tennat_type',
    },
  },
  
];



export const formPermissionSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'name',
    label: '套餐名称',
    component: 'Input',
    required: true
  },
  {
    label: '状态',
    field: 'status',
    required: true,
    defaultValue: '1',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'data_use_status',
      placeholder:'请选择状态',
      type: "radio",
    }
  },
  {
    field: 'tenantType',
    label: '租户类型',
    component: 'JDictSelectTag',
    defaultValue: '3',
    ifShow: ({ values }) => userStore.getSelectTenant.tenantType === TenantType.PLATFORM ,
    required: ({ values }) => userStore.getSelectTenant.tenantType === TenantType.PLATFORM ,
    componentProps: {
      type: 'radio',
      dictCode: 'tenant_type',
    },
  },
  {
    label: '场景',
    required: true,
    field: 'sceneId',
    dynamicDisabled: ({ values }) => {
      return !!values.id || userStore.getSelectTenant.tenantType != TenantType.PLATFORM ;
    },
    component: 'ApiSelect'
  }
];